package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.AdminOrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "订单管理")
public class AdminOrderController {
    @Autowired
    private AdminOrderService adminOrderService;

    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result OrderSearch(OrdersPageQueryDTO dto){
        PageResult page = adminOrderService.OrderSearch(dto);
        return Result.success(page);
    }

    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result Statistics(){
        OrderStatisticsVO vo=adminOrderService.Statistics();
        vo.getConfirmed();
        return Result.success(vo);
    }
    @GetMapping("/details/{id}")
    @ApiOperation("根据ID查询订单详情")
    public Result finById(@PathVariable("id") String id){
        OrderVO vo=adminOrderService.finById(id);
        return Result.success(vo);
    }
    @PutMapping("complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable("id")String id){
        adminOrderService.complete(id);
        return Result.success();
    }
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO dto){
        adminOrderService.cancel(dto);
        return Result.success();
    }
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody OrdersConfirmDTO dto){
        adminOrderService.confirm(dto);
        return Result.success();
    }
    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO dto){
        adminOrderService.rejection(dto);
        return Result.success();
    }
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送")
    public Result delivery(@PathVariable("id") String id){
        adminOrderService.delivery(id);
        return Result.success();
    }

}
